<?php
/**
 * 用户管理模型
 * 
 * @author  Lee<a605333742@gmail.com>
 * @time    2016-07-25
 */
namespace Model;
use Think\Model;

class BuyModel extends Model{
       
    /*
     * 删除,禁用，审核，待审核求购信息
     * 
     * @return bool
     */
    public function edits($where){
        $g  =$where['id'];
        if(is_array($where['id'])){
            $g  =implode(',',$where['id']);
            $where['id']=array("in",implode(',',$where['id']));            
        }
        if($this->save($where)){
            $data=array(
                "user_id"   =>session("authId"),
                'content'   =>"编辑了id为 ".$g." 的求购信息",
                "add_time"  =>time()
            );
            if(M("Log")->add($data)){
                return TRUE;
            }else{
                return FALSE;
            }
        }
    }
    
    /*
     * 编辑求购信息
     * 
     * @return bool
     */
    public function buyEdit($where){
        $g='';
        if($where['id']){
            //id存在为修改
             if($where['top_sign']){
                $top            =$this->max("top");
                $where['top']   =$top+1;
             }
            if($this->save($where)){
                $g="修改";                
            }else{
                return FALSE;
            }
        }else{
            //否则为新增 
            $top            =$this->max("top");
            $where['top']   =$top+1;
            if($this->add($where)){
                $g="新增";                
            }else{
                return FALSE;
            }
        }
        $data=array(
            'user_id'   =>session("authId"),
            'content'   =>$g.'了名为 '.$where['title'].' 的求购信息',
            'add_time'  =>time()
        );
        if(M("Log")->add($data)){
            return TRUE;
        }else{
            return FALSE;
        }
    }
}